home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX Installation Tools & Overlays 2002 November
/
SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso
/
dist
/
infosearch.idb
/
usr
/
lib
/
infosearch
/
bin
/
relnotesTOC.z
/
relnotesTOC
Wrap
Text File
|
2002-10-15
|
7KB
|
333 lines
#!/usr/bin/perl
require 5;
$bgcolor ="#f9f9f9";
$doctype = "<!DOCTYPE HTML PUBLIC \"-//Netscape " .
"Comm. Corp.//DTD HTML//EN\">\n";
$comment = "<!-- Generated by infosearch relnotesTOC -->\n";
$bHTML = "<HTML>\n";
$eHTML = "</HTML>\n";
$bTitle = "<HEAD>\n <TITLE>";
$eTitle = "</TITLE>\n</HEAD>\n";
$bBody = "<BODY BGCOLOR=\"$bgcolor\">";
$eBody = "</BODY>\n";
$cgiBase = "<A HREF=\"/cgi-bin/infosrch.cgi?cmd=getdoc&db=relnotes&fname=";
$bBQ = "<P>";
$eBQ = "</P>";
$sgiIndex = "/usr/relnotes/SGIindex/relnotes.ttl";
$arg1 = $ARGV[0];
# if -coll then add "&coll=" to the getdoc URL
if ($ARGV[1] eq "-coll" && $cgiBase =~ /(.*)&db=relnotes(.*)/) {
$cgiBase = $1 . "&coll=" . $ARGV[2] . "&db=relnotes" . $2;
shift; shift;
}
if ($arg1 eq ""){
&buildFTIndexList("$sgiIndex");
}elsif($arg1=~/\.ttl/){
&buildFTIndexList($arg1);
}elsif($arg1=~/relnotes\.html/){
&buildTOCnoIndex(); # fallback index to STDOUT
}
#######################################################################
#
# buildFTIndexList()
#
#######################################################################
sub buildFTIndexList{
local($titlefiles) = @_;
local($inBQ) = 0;
local($lastAlpha) = "";
local($thisAlpha) = "";
unless( -r $titlefiles ){
die "Unable to read $titlefiles\n";
}
$mainIndexTTL = $titlefiles;
$htmlTOC = $titlefiles;
$htmlTOC =~ s/\.ttl/\.html/;
$localIndexTTL = $mainIndexTTL;
$localIndexTTL =~ s/([^\/]*)\.ttl$/local$1\.ttl/;
# Only if the local file exists (else strings error)
if ( -e $localIndexTTL ){
$titlefiles = "$titlefiles $localIndexTTL";
}
open(TITLESTR, "strings $titlefiles | " )
|| die "Error: Can't open $titlefiles\n";
@titledata=();
@toclist=();
while(<TITLESTR>){
if (/^F(.+)\n/){
# Take the filename exactly as it appears in the index
# title file (.ttl file).
$filename=$1;
}elsif(/^t(.+)\n/){
push(@titledata, $1);
push(@toclist, "$1\t$filename");
}
}
close(TITLESTR);
@toclist = sort sortCaseInsensitive @toclist;
system("rm -f $htmlTOC");
open(TOCFD,">> $htmlTOC")
|| die "Can't open $htmlTOC\n";
&HTMLFileHeader(TOCFD,"Product Release Notes");
&alphaHeader(TOCFD);
foreach(@toclist){
if(/([^\t]+)\t([^\t]+)/ && ($prod = $1, $file = $2)){
$file =~ s/\+/%2b/g; # Files with + break the cgi
$thisAlpha=&setAlpha($prod);
&alphaIndexIfNeeded($inBQ,TOCFD,$lastAlpha,$thisAlpha);
$lastAlpha = $thisAlpha;
if($inBQ == 0){ # Correct indentation
$indent = $bBQ;
$inBQ = 1;
}else{
$indent = "";
}
print TOCFD
" ",
"$cgiBase$file\">$prod</A><BR>\n"
or die "print: $!";
}
}
&HTMLFileTrailer(TOCFD);
}
#######################################################################
#
# buildTOCnoIndex
#
# Build a table of contents from relnote files
#
#######################################################################
sub buildTOCnoIndex{
local($inBQ) = 0;
local($lastAlpha) = "";
local($thisAlpha) = "";
local(@relprods) = ();
local($relpath) = $ENV{'RELNOTESPATH'};
if($relpath eq ""){
$relpath = "/usr/relnotes";
}
$relfind = "find $relpath -name TC -print";
open(RELFIND,"$relfind |")
|| die "Can't open $htmlTOC\n";
while(<RELFIND>){
if(/\/([^\/]+)\/TC/){
push(@relprods,$1);
}
}
@relprods = sort sortCaseInsensitive @relprods;
&HTMLFileHeader(STDOUT,"Product Release Notes");
&alphaHeader(STDOUT);
foreach(@relprods){
$cgitrans = $_;
$cgitrans =~ s/\+/%2b/g; # Products with '+' break the cgi
$thisAlpha=&setAlpha($_);
&alphaIndexIfNeeded($inBQ,STDOUT,$lastAlpha,$thisAlpha);
$lastAlpha = $thisAlpha;
if($inBQ == 0){ # Correct indentation
$indent = $bBQ;
$inBQ = 1;
}else{
$indent = "";
}
print
"${indent}",
"$cgiBase$cgitrans\">$_</A><BR>\n"
or die "print: $!";
}
&HTMLFileTrailer(STDOUT);
}
#######################################################################
#
# HTMLFileHeader(fd, title)
#
#######################################################################
sub HTMLFileHeader{
local($filehandle,$title)= @_;
print { $filehandle }
"$doctype$comment$bHTML$bTitle$title$eTitle$bBody\n"
or die "print: $!";
print { $filehandle }
"<H3>$title</H3>\n"
or die "print: $!";
}
#######################################################################
#
# HTMLFileTrailer(fd)
#
#######################################################################
sub HTMLFileTrailer{
local($filehandle) = @_;
print { $filehandle } "${eBQ}${eBody}${eHTML}"
or die "print: $!";
}
#######################################################################
#
# sortCaseInsensitive
#
#######################################################################
sub sortCaseInsensitive
{
local($tmp_a) = $a;
local($tmp_b) = $b;
$tmp_a =~ tr/A-Z/a-z/;
$tmp_b =~ tr/A-Z/a-z/;
return($tmp_a cmp $tmp_b);
}
#######################################################################
#
# setAlpha(titleString)
#
#######################################################################
sub setAlpha{
local($title) = @_;
local($alpha) = "";
if($title=~/^([a-zA-Z])/){
$alpha=$1;
$alpha=~tr/a-z/A-Z/;
}
return $alpha;
}
#######################################################################
#
# alphaHeader()
#
#######################################################################
sub alphaHeader{
local($filehandle) = @_;
local(@alphabet) =
(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
print {$filehandle} "${bBQ}<B>\n" or die "print: $!";
foreach(@alphabet){
print {$filehandle} "<A HREF=\"#$_\">$_</A> \n"
or die "print: $!";
}
print {$filehandle} "</B>${eBQ}<BR>\n"
or die "print: $!";
}
#######################################################################
#
# alphaIndex($inBQ,$fd,$lastAlpha,$thisAlpha)
#
#######################################################################
sub alphaIndexIfNeeded{
local($fd);
($inBQ, $fd, $lastAlpha, $thisAlpha) = @_;
local(@alphabet) =
(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z);
if($thisAlpha ne $lastAlpha && $thisAlpha ne ""){
if($inBQ == 1){
$exdent = "$eBQ\n";
$inBQ = 0;
}else{
$exdent = "";
}
$off = (ord($thisAlpha)-ord($lastAlpha));
print {$fd} $exdent or die "print: $!";
if($off > 1 && $lastAlpha ne ""){
local($a) = 0;
while($lastAlpha ne $alphabet[$a]){
$a++;
}
$a = $a+1;
for($j=0;$j<$off;$j++){
print {$fd} "<H3><A NAME=\"$alphabet[$j+$a]\">" .
"$alphabet[$j+$a]</A></H3>\n"
or die "print: $!";
}
}else{
print {$fd} "<H3><A NAME=\"$thisAlpha\">" .
"$thisAlpha</A></H3>\n"
or die "print: $!";
}
}
$lastAlpha = $thisAlpha;
}